package cn.iocoder.yudao.module.cdk.service.cdkuser;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.cdk.controller.app.cdkuser.vo.CdkappuserPageReqVO;
import cn.iocoder.yudao.module.cdk.controller.app.cdkuser.vo.CdkappuserSaveReqVO;
import cn.iocoder.yudao.module.cdk.dal.dataobject.cdkuser.CdkuserDO;
import cn.iocoder.yudao.module.cdk.dal.mysql.cdkuser.CdkappuserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.cdk.enums.ErrorCodeConstants.USER_NOT_EXISTS;

/**
 * cdk使用用户 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CdkappuserServiceImpl implements CdkappuserService {

    @Resource
    private CdkappuserMapper userappcdkMapper;

    @Override
    public Integer createuser(CdkappuserSaveReqVO createReqVO) {
        Long count =  userappcdkMapper.selectCount("name", createReqVO.getName());
        if (count==0){

            // 插入
            CdkuserDO user = BeanUtils.toBean(createReqVO, CdkuserDO.class);
            userappcdkMapper.insert(user);

        }else if (count>=1){

        }

        return 1;
        // 返回
    }

    private void validateuserExists(Integer id) {
        if (userappcdkMapper.selectById(id) == null) {
            throw exception(USER_NOT_EXISTS);
        }
    }

    @Override
    public CdkuserDO find(String id) {
        return null;
    }

}